"""
选择排序：O(n^2)
"""


def select_sort(sequence):
    for i in range(len(sequence)-1):
        min_index = i    # 记录最小数的索引值
        for j in range(i+1, len(sequence)):
            if sequence[j] < sequence[min_index]:
                min_index = j

        sequence[min_index], sequence[i] = sequence[i], sequence[min_index]

    return sequence


if __name__ == '__main__':
    sequence = [12, 27, 46, 16, 25, 37, 22, 29, 15, 47, 48, 34]
    print(sequence)
    print(select_sort(sequence))

